$('.text').focus(function(){
    $(this).prop('placeholder','')
    
}).blur(function(){
   if($(this).val() == ''){
    $(this).prop('placeholder','请输入用户名')
    $('.alertText').css({
        visibility: 'visible'
    })
   }else{
    $('.alertText').css({
        visibility: 'hidden'
    })
   }
})
$('.psd').focus(function(){
    $(this).prop('placeholder','')
}).blur(function(){
   if($(this).val() == ''){
    $(this).prop('placeholder','请输入密码')
    $('.alertPsd').css({
        visibility: 'visible'
    })
   }else{
    $('.alertPsd').css({
        visibility: 'hidden'
    })
   }
})
$('#top .logo').click(function(){
    location.href = '../pages/index.html'
})

$('form').submit(function(e){
    e.preventDefault()
    if($('.psd').val() == '' || $('.text').val() == ''){
      if($('.psd').val() == '' && $('.text').val() == ''){
          alert('注册失败，请填写用户名和密码')
          return
      }
      if($('.psd').val() == ''){
        alert('注册失败，请填写密码')
        return
      }
      if($('.text').val() == ''){
        alert('注册失败，请填写用户名')
        return
      }
    }
  
    let personStr = localStorage.getItem('PERSON')
    let personArr = JSON.parse(personStr) || []
    let obj = {
        username:$('.text').val(),
        password:$('.psd').val()
    }
    let person = personArr.find(function(item){
        return item.username == obj.username
    })
    if(person){
        alert('已存在该昵称的用户')
        return
    }else{
        personArr.push(obj)
    }
    // console.log($('.text').val());
    localStorage.setItem('PERSON',JSON.stringify(personArr))
    axios({
		method: 'post',
		url: 'http://api.yuguoxy.com/api/member/add',
        data:{
            username:$('.text').val(),
            password:$('.psd').val(),
        }
	}).then(response => {
        console.log(response);
		let  resultInfo  = response.data.resultInfo
        $('.text').val('').prop('placeholder','请输入用户名')
        $('.psd').val('').prop('placeholder','请输入密码')
        alert('注册成功')
		
    }) 
})